Skip to content

Conversation

@Ericson2314
Copy link
Member

Motivation

nix derivation add, and its C API counterpart, now works a bit closer to builtins.derivation in that they don't require the user to fill-in input addressed paths correctly ahead of time.

The logic for this is carefully deduplicated, between all 3 entry points, and also between the existing checkInvariants function. There are some more functional tests, and there are also many more unit tests.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority c api Nix as a C library with a stable interface labels Nov 13, 2025
*
* @param store The store to use for validation
*/
void checkInvariants(Store & store) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this version needed now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in parseJsonAndValidate, we validate the derivation before we compute its drvPath now. The drvPath was just used for error messages, but it we can write a better error message --- since we just computed the drv path, it won't mean anything to the human reading the error anyways where ("derivation from JSON" or similar will)


# If we remove the input addressed to make it a deferred derivation, we
# still get the same result because Nix will see that need not be
# deferred and fill in the right input address for us.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a good thing? From reading checkInvariants, it looks like this is new behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkInvariants doesn't do this, but fillInOutputPaths does. It is new behavior in the JSON code path, but not new behavior in the builtins.derivation code path.

return;
}
auto & value = j->second;
if (value == "") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this actually happen - I did not see it in the old code?

Copy link
Member Author

@Ericson2314 Ericson2314 Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user-submitted JSON is arbitrary data, so yes it can happen. It also does happen in the builtins.derivationStrict code path already.

@Ericson2314 Ericson2314 force-pushed the fill-in-outputs branch 2 times, most recently from 8149291 to 745c307 Compare November 17, 2025 19:50
@Ericson2314 Ericson2314 force-pushed the fill-in-outputs branch 7 times, most recently from 7f3f8f1 to 79cf901 Compare November 19, 2025 19:54
Ericson2314 and others added 2 commits November 20, 2025 00:49
These do a read/write test in the middles of some computation. They are
an imperative way to test intermediate values rather than functionally
testing end outputs.
`nix derivation add`, and its C API counterpart, now works a bit closer
to `builtins.derivation` in that they don't require the user to fill-in
input addressed paths correctly ahead of time.

The logic for this is carefully deduplicated, between all 3 entry
points, and also between the existing `checkInvariants` function. There
are some more functional tests, and there are also many more unit tests.

Co-authored-by: Sergei Zimmerman <[email protected]>
Co-authored-by: edef <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c api Nix as a C library with a stable interface new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants